//
//  YKCategoryDetailController.m
//  HMPersonalDoctor
//
//  Created by 叶文凯 on 16/9/8.
//  Copyright © 2016年 geduo. All rights reserved.
//

#import "YKCategoryDetailController.h"
#import "YKSelectIllnessController.h"
#import "YKCompTabController.h"
#import "YKDoctorModel.h"

@interface YKCategoryDetailController ()

@property(weak,nonatomic)UIButton *isSureBtn;
@property(weak,nonatomic)UIButton *isHistoryBtn;
@property(weak,nonatomic)UIImageView *docImageView;
@property(weak,nonatomic)UILabel *doctLabel;
@end

@implementation YKCategoryDetailController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"选择病症";
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    
    [self setupUI];

}

- (void)setupUI
{
    
    UILabel *illType = [[UILabel alloc] init];
    illType.font = [UIFont systemFontOfSize:18];
    illType.textColor = [UIColor blackColor];
    illType.text = [NSString stringWithFormat:@"疾病分类：%@",self.name];
    [self.view addSubview:illType];
    [illType sizeToFit];
    [illType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(15);
        make.top.equalTo(self.view).offset(70);
    }];
    
#pragma mark -    第一个button 选择病症
    UIButton *selectTypeBtn = [[UIButton alloc] init];
    //    smallTypeBtn.
    //    smallTypeBtn.imageView.image = [UIImage imageNamed:@"illness_button_input_blue.png"];
    selectTypeBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    selectTypeBtn.layer.cornerRadius = 10;
    selectTypeBtn.layer.masksToBounds = YES;
    selectTypeBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    selectTypeBtn.layer.borderWidth = 1.0;
    
    [selectTypeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    selectTypeBtn.titleLabel.font =[UIFont systemFontOfSize:14];
   
    [self.view addSubview:selectTypeBtn];
    
    [selectTypeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(13);
        make.top.equalTo(illType.mas_bottom).offset(20);
        make.right.equalTo(self.view).offset(-15);
        make.height.mas_equalTo(36);
    }];
    
    
    //   选择病症按钮事件
    [selectTypeBtn addTarget:self action:@selector(smallTypeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    UILabel *smallTypelabel = [[UILabel alloc] init];
    smallTypelabel.text = @"选择病症:";
    smallTypelabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:smallTypelabel];
    
    [smallTypelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).offset(17);
        make.top.equalTo(illType.mas_bottom).offset(27);
        
    }];
    
    
#pragma mark -    设置的第二个button 症状
    
    UIButton *symptomButton = [[UIButton alloc] init];
    symptomButton.layer.cornerRadius = 10.0;
    symptomButton.layer.masksToBounds = YES;
    symptomButton.layer.borderWidth = 1.0;
    symptomButton.layer.borderColor = [UIColor lightGrayColor].CGColor;
    
    
    [symptomButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    symptomButton.titleLabel.font =[UIFont systemFontOfSize:14];
    [self.view addSubview:symptomButton];
    [symptomButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).offset(13);
        make.top.equalTo(selectTypeBtn.mas_bottom).offset(15);
        make.right.equalTo(self.view).offset(-15);
        make.height.mas_equalTo(36);
        
    }];
    
    //    添加并发症状按钮事件
    
    [symptomButton addTarget:self action:@selector(symptomButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel *symptomLabel = [[UILabel alloc] init];
    symptomLabel.text = @"并发症状:";
    symptomLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:symptomLabel];
    
    [symptomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(17);
        make.top.equalTo(selectTypeBtn.mas_bottom).offset(25);
    }];
    
#pragma mark -    第三个按钮:
    
    UIButton *isSureBtn = [[UIButton alloc] init];
    
    isSureBtn.layer.cornerRadius = 10.0;
    isSureBtn.layer.masksToBounds = YES;
    isSureBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    isSureBtn.layer.borderWidth = 1.0;
    [self.view addSubview:isSureBtn];
    
    [isSureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).offset(13);
        make.top.equalTo(symptomButton.mas_bottom).offset(25);
        make.right.equalTo(self.view).offset(-15);
        make.height.mas_equalTo(44);
        
    }];
    
    UILabel *isSureLabel = [[UILabel alloc] init];
    isSureLabel.text = @"是否确诊:";
    isSureLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:isSureLabel];
    [isSureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).offset(17);
        make.top.equalTo(symptomButton.mas_bottom).offset(36);
        
    }];
    
    //   确诊按钮：
    UIButton *sureBtn = [[UIButton alloc] init];
    sureBtn.layer.cornerRadius = 8;
    sureBtn.layer.masksToBounds = YES;
    sureBtn.layer.borderWidth = 1;
    sureBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    [self.view addSubview:sureBtn];
    sureBtn.tag = 1;
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(isSureBtn);
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
    
    //    添加确诊按钮方法
    [sureBtn addTarget:self action:@selector(isSureAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *sureLabel = [[UILabel alloc] init];
    sureLabel.text = @"确诊";
    sureLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:sureLabel];
    
    [sureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(sureBtn);
        make.centerX.equalTo(sureBtn).offset(30);
    }];
    
    //   没有确诊按钮
    UIButton *notSureBtn = [[UIButton alloc] init];
    notSureBtn.layer.cornerRadius = 8;
    notSureBtn.layer.masksToBounds = YES;
    notSureBtn.layer.borderWidth = 1;
    notSureBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    [self.view addSubview:notSureBtn];
    notSureBtn.tag = 2;
    [notSureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(sureLabel.mas_right).offset(10);
        make.centerY.equalTo(isSureLabel);
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
    
    //    添加没有确诊方法
    [notSureBtn addTarget:self action:@selector(isSureAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *notSureLabel = [[UILabel alloc] init];
    notSureLabel.text = @"未确诊";
    notSureLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:notSureLabel];
    
    [notSureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(notSureBtn);
        make.left.equalTo(notSureBtn.mas_right).offset(5);
    }];
    
    
    
#pragma mark -    是否有过病史
    
    UIButton *isHistoryBtn = [[UIButton alloc] init];
    
    isHistoryBtn.layer.cornerRadius = 10.0;
    isHistoryBtn.layer.masksToBounds = YES;
    isHistoryBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    isHistoryBtn.layer.borderWidth = 1.0;
    [self.view addSubview:isHistoryBtn];
    isHistoryBtn.tag = 3;
    [isHistoryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).offset(13);
        make.top.equalTo(isSureBtn.mas_bottom).offset(25);
        make.right.equalTo(self.view).offset(-15);
        make.height.mas_equalTo(44);
        
    }];
    
    
    UILabel *isHistoryLabel = [[UILabel alloc] init];
    isHistoryLabel.text = @"是否有病史:";
    isHistoryLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:isHistoryLabel];
    [isHistoryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(isHistoryBtn).offset(3);
        make.centerY.equalTo(isHistoryBtn);
    }];
    
    //    确认按钮
    UIButton *yesBtn = [[UIButton alloc] init];
    yesBtn.layer.cornerRadius = 8;
    yesBtn.layer.masksToBounds = YES;
    yesBtn.layer.borderWidth = 1;
    yesBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    [self.view addSubview:yesBtn];
    
    [yesBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(isHistoryBtn).offset(-20);
        make.centerY.equalTo(isHistoryBtn);
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
    
    //    有病史按钮点击事件
    [yesBtn addTarget:self action:@selector(isHistoryAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *yesLabel = [[UILabel alloc] init];
    yesLabel.text = @"有过病史";
    yesLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:yesLabel];
    
    [yesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(yesBtn);
        make.left.equalTo(yesBtn.mas_right).offset(3);
    }];
    
    
    //  没有病史按钮
    UIButton *noBtn = [[UIButton alloc] init];
    noBtn.layer.cornerRadius = 8;
    noBtn.layer.masksToBounds = YES;
    noBtn.layer.borderWidth = 1;
    noBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    [self.view addSubview:noBtn];
    
    [noBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(yesLabel.mas_right).offset(10);
        make.centerY.equalTo(yesLabel);
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
    //没有病史按钮点击事件
    [noBtn addTarget:self action:@selector(isHistoryAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel *noLabel = [[UILabel alloc] init];
    noLabel.text = @"没有病史";
    noLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:noLabel];
    
    [noLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(yesBtn);
        make.left.equalTo(noBtn.mas_right).offset(3);
    }];
    
    
#pragma mark - 治疗方式按钮
    
    UIButton *cureStyleBtn = [[UIButton alloc] init];
    
    cureStyleBtn.layer.cornerRadius = 10.0;
    cureStyleBtn.layer.masksToBounds = YES;
    cureStyleBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    cureStyleBtn.layer.borderWidth = 1.0;
    [self.view addSubview:cureStyleBtn];
    cureStyleBtn.tag = 3;
    
    [cureStyleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    cureStyleBtn.titleLabel.font =[UIFont systemFontOfSize:14];
    
    [cureStyleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).offset(13);
        make.top.equalTo(isHistoryBtn.mas_bottom).offset(30);
        make.right.equalTo(self.view).offset(-15);
        make.height.mas_equalTo(36);
        
    }];
    //    添加治疗方式按钮事件
    [cureStyleBtn addTarget:self action:@selector(cureStyleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    //    治疗方式 ：
    UILabel *cureStyleLabel = [[UILabel alloc] init];
    cureStyleLabel.text = @"治疗方式:";
    cureStyleLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:cureStyleLabel];
    [cureStyleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(cureStyleBtn).offset(3);
        make.centerY.equalTo(cureStyleBtn);
    }];
    
    
    
#pragma mark - 预约医生
    
    UILabel *showDoctorLabel = [[UILabel alloc] init];
    showDoctorLabel.text = [NSString stringWithFormat:@"为您预约了~"];
    
    [self.view addSubview:showDoctorLabel];
    
    [showDoctorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(cureStyleBtn.mas_bottom).offset(20);
    }];
    
    UILabel *doctLabel = [[UILabel alloc] init];
//    doctLabel.text = @"骨科医生 华佗";
    doctLabel.textColor = [UIColor orangeColor];
    [self.view addSubview:doctLabel];
    self.doctLabel = doctLabel;
    [doctLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(showDoctorLabel.mas_bottom).offset(8);
    }];
    
    

//   测试代码
    
//    CALayer *layer = [CALayer layer];
//    
//    layer.backgroundColor = [UIColor orangeColor].CGColor;
//    layer.bounds = CGRectMake(0, 0, 100, 100);
//    
//    layer.position = CGPointMake(self.view.frame.size.width/2, 500);
//    
//    layer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"图层-1"].CGImage);
//    
//    [self.view.layer addSublayer:layer];
    
//    imgView.layer
    
    
  //    显示医生图片
    UIImageView *docImageView = [[UIImageView alloc] init];

    self.docImageView = docImageView;
    [self.view addSubview:docImageView];
    
//    docImageView.backgroundColor = [UIColor orangeColor];
    
    [docImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(showDoctorLabel.mas_bottom).offset(38);
        make.size.mas_equalTo(CGSizeMake(100, 100));
        
    }];

    
    
#pragma mark - 预约医生按钮
    
    UIButton *orderDoctorBtn = [[UIButton alloc] init];
    [orderDoctorBtn setTitle:@"预约医生" forState:UIControlStateNormal];
    orderDoctorBtn.layer.cornerRadius = 10;
    orderDoctorBtn.layer.masksToBounds = YES;
    orderDoctorBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    orderDoctorBtn.layer.borderWidth = 1.0;
    [orderDoctorBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [orderDoctorBtn setBackgroundColor:[UIColor orangeColor]];
    [self.view addSubview:orderDoctorBtn];
    
    [orderDoctorBtn addTarget:self action:@selector(orderDoctorAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    [orderDoctorBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.view.mas_bottom).offset(-10);
        make.centerX.equalTo(self.view);
        make.width.mas_equalTo(100);
    }];
    
}




#pragma mark - 单选按钮实现方法
- (void)isSureAction:(UIButton *)button
{
    
    self.isSureBtn.backgroundColor = [UIColor whiteColor];
    button.backgroundColor = [UIColor greenColor];
    
    self.isSureBtn = button;
    
}
- (void)isHistoryAction:(UIButton *)button
{
    
    self.isHistoryBtn.backgroundColor = [UIColor whiteColor];
    button.backgroundColor = [UIColor greenColor];
    
    self.isHistoryBtn = button;
    
    
}

#pragma mark - 选择病状按钮事件
- (void)smallTypeBtnClick:(UIButton *)button
{
    
    YKSelectIllnessController *selectIllController = [[YKSelectIllnessController alloc] init];
    
    [selectIllController setNameBlock:^(NSString *name) {
        
        [button setTitle:name forState:UIControlStateNormal];
        
    }];
    selectIllController.name = self.name;
    
    [self.navigationController pushViewController:selectIllController animated:YES];
    
}

#pragma mark - 并发症状按钮事件

- (void)symptomButtonClick:(UIButton *)button
{
    YKCompTabController *compController = [[YKCompTabController alloc] init];
    
    [compController setCompBlock:^(NSArray *namelist) {
        
        NSMutableString *string = [NSMutableString string];
        [namelist enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            [string appendFormat:@"%@ ",obj];
            
        }];
        
        
        [button setTitle:string forState:UIControlStateNormal];
        
    }];
    
    [self.navigationController pushViewController:compController animated:YES];
    
}

#pragma mark - 治疗方式按钮事件

- (void)cureStyleBtnAction:(UIButton *)button
{
    YKSelectIllnessController *selectIllController = [[YKSelectIllnessController alloc] init];
    
    selectIllController.tag = button.tag;
    [selectIllController setStyleBlock:^(NSString *style) {
        
        [button setTitle:style forState:UIControlStateNormal];
        
    }];
    
    [self.navigationController pushViewController:selectIllController animated:YES];
    
}

#pragma mark - 预约医生按钮点击事件

- (void)orderDoctorAction:(UIButton *)button
{
    for (YKDoctorModel * model in self.modelList) {
        
        if ( [model.name isEqualToString: self.name]) {
            
             self.doctLabel.text = [NSString stringWithFormat:@"%@医生 %@",self.name,model.xing];
            
               self.docImageView.image = [UIImage imageNamed:model.icon];
        }
 
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

- (void)setName:(NSString *)name
{
    _name = name;
    
    
}

- (void)setModelList:(NSArray *)modelList
{
    _modelList = modelList;
    
    
    
    
}


@end
